﻿using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using Controller;
public partial class Processo : System.Web.UI.Page
{

    private DS_Lawyer.ProcessoDataTable dtProcesso
    {
        set { ViewState["dtProcesso"] = value; }
        get
        {
            object o = ViewState["dtProcesso"];
            if (o == null)
                return null;
            else
                return (DS_Lawyer.ProcessoDataTable)o;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
         if (!Page.IsPostBack)
        {
            String idClente = Request.QueryString["IDCliente"];

            try
            {
                if (idClente == null)
                    this.dtProcesso = cntrProcesso.Select();
                else
                    this.dtProcesso = cntrProcesso.SelectByCliente(idClente);
                    

                grdProcessos.DataSource = this.dtProcesso;
                grdProcessos.DataBind();
            }
            catch (Exception ex)
            {

                throw (new Exception(ex.Message));
            }
        }
    }

    protected void grdProcessos_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            string idProcesso = this.dtProcesso[index].idProcesso;
            Response.Redirect("NewProcesso.aspx?IDProcesso=" + idProcesso);

        }

        if (e.CommandName == "MudarStatus")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            string idProcesso = this.dtProcesso[index].idProcesso;
            cntrProcesso objCntrProcesso = new cntrProcesso();

            DS_Lawyer.ProcessoRow rowProcesso = objCntrProcesso.Select(idProcesso);

            objCntrProcesso.MudarStatus(rowProcesso);

            this.dtProcesso = cntrProcesso.Select();
            grdProcessos.DataSource = this.dtProcesso;
            grdProcessos.DataBind();
            

        }

    }
   
    protected string GetImage(string pStatus)
    {
        string ret = "";
        if (pStatus == "1")
           ret = "~/Images/fechado.png";
        else
            ret = "~/Images/aberto.png";
        return ret;
    }

    protected void btnPesquisar_Click(object sender, ImageClickEventArgs e)
    {
        string criterio = txtBuscaNome.Text.Trim();

        this.dtProcesso = cntrProcesso.SelectByName(criterio);
        grdProcessos.DataSource = this.dtProcesso;
        grdProcessos.DataBind();
    }
}
